package com.ylsf.blog.service.impl;

import com.ylsf.blog.exception.PublishArticleException;
import com.ylsf.blog.mapper.ArticleMapper;
import com.ylsf.blog.pojo.Article;
import com.ylsf.blog.service.EditService;
import com.ylsf.blog.utils.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * 编辑服务实现类
 */
public class EditServiceImpl implements EditService {
    @Override
    public Integer publishArticle(Article article){
        SqlSession sqlSession=null;
        Integer integer=0;
        try {
            sqlSession = SqlSessionUtil.openSession();
            ArticleMapper articleMapper = sqlSession.getMapper(ArticleMapper.class);
            integer = articleMapper.insertArticle(article);
            sqlSession.commit(); // 将提交操作放在try块中
        }catch (Exception e) {
            if (sqlSession != null) {
                sqlSession.rollback(); // 在catch块中进行回滚操作
            }
        }finally {
            if (sqlSession != null) {
                SqlSessionUtil.close(sqlSession); // 在finally块中关闭SqlSession
            }
        }
        return integer;
    }
}
